import { defHttp } from '/@/utils/http/axios';
import { ContentTypeEnum } from '@/enums/httpEnum';
import { QueryProductSpecVo } from '@/api/base-data/product/spec/model/queryProductSpecVo';
import { QueryProductSpecBo } from '@/api/base-data/product/spec/model/queryProductSpecBo';
import { GetProductSpecBo } from '@/api/base-data/product/spec/model/getProductSpecBo';
import { ProductSpecVo } from '@/api/base-data/product/spec/model/productSpecVo';

const baseUrl = '/basedata/product/spec';
const region = 'cloud-api';

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryProductSpecVo): Promise<QueryProductSpecBo[]> {
  return defHttp.get<QueryProductSpecBo[]>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetProductSpecBo> {
  return defHttp.get<GetProductSpecBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 新增
 * @param productId
 * @param params
 * @returns {Promise}
 */
export function save(productId: String, params: ProductSpecVo[]): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl + '/' + productId,
      data: params,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}
